<template>
	<view class="result">
		<Hearder :name="'支付结果'"></Hearder>
		<view class="content" v-if="success==0">
			<image src="/static/images/shibai.png"></image>
			<view class="title">支付失败</view>
			<view class="desc">请重新支付，完成订单</view>
			<view class="btn_box clearfix">
				<view @click="toSwitch('/pages/Client/personal')">返回商品</view>
				<view @click="paymoney">重新支付</view>
			</view>
		</view>
		<view class="content" v-if="success==1">
			<image src="/static/images/785.png"></image>
			<view class="title">支付成功</view>
			<view class="desc">商品正在备货，请耐心等待</view>
			<view class="btn_box clearfix">
				<view @click="toPage('/pages/classify/goodsdet?id='+goods_id)">返回商品</view>
				<view @click="toPage('/pages/classify/order?type=forwarding')">查看订单</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				success:1,
				type:1,
				goods_id:''
			}
		},
		onLoad(options) {
			// this.success= options.success || this.$route.query.success
			// this.type= options.type || this.$route.query.type
			this.goods_id = options.id || this.$route.query.id
		},
		methods:{
			paymoney(){
				var that = this
				uni.login({
					success: function (data) {
						if(that.type==2){
							that.request({
								url:'/alliance/applyalliance/alliancePay',
								method: "POST",
								data:{code:data.code},
								success: (res) => {
									if(res.data.code==200){
										uni.requestPayment({
										  timeStamp: res.data.data.timeStamp,
										  nonceStr: res.data.data.nonceStr,
										  package: res.data.data.package,
										  signType: res.data.data.signType,
										  paySign: res.data.data.paySign,
										  success: function(res) {
											uni.redirectTo({
												url:'/pages/common/result?success=1&type=2'
											})
										  }
										});
									}else{
										uni.redirectTo({
											url:'/pages/common/result?success=0&type=2'
										})
									}
								}
							});
						}else{
							that.request({
								url:'/merchant/applyMerchant/pay',
								method: "POST",
								data:{code:data.code},
								success: (res) => {
									if(res.data.code==200){
										uni.requestPayment({
										  timeStamp: res.data.data.timeStamp,
										  nonceStr: res.data.data.nonceStr,
										  package: res.data.data.package,
										  signType: res.data.data.signType,
										  paySign: res.data.data.paySign,
										  success: function(res) {
											uni.redirectTo({
												url:'/pages/common/result?success=1&type=1'
											})
										  }
										});
									}else{
										uni.redirectTo({
											url:'/pages/common/result?success=0&type=1'
										})
									}
								}
							});
						}
					},
				})
			},
			toSwitch(route){
				uni.switchTab({
				    url: route
				});
			},
			toPage(route){
				uni.redirectTo({
				    url: route
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.result{
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		.content{
			text-align: center;
			image{
				width: 230rpx;
				height: 200rpx;
			}
			.title{
				font-size: 32rpx;
				font-weight: 800;
				margin-top: 30rpx;
				text-align: center;
			}
			.desc{
				font-size: 24rpx;
				color: #999;
				text-align: center;
				margin-top: 20rpx;
			}
			.btn_box{
				margin-top: 70rpx;
				view{
					float: left;
					width: 298rpx;
					height: 88rpx;
					border-radius: 88rpx;
					text-align: center;
					line-height: 88rpx;
					border: 1rpx solid $uni-item-color;
					color: $uni-item-color;
					&:last-of-type{
						margin-left: 20rpx;
						background: $uni-item-color;
						color: #fff;
					}
				}
			}
		}
	}
</style>
